package day08_stream_file_charset.com.itheima.d1_stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Stream;

public class Test3_Stream {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "张三", "李四", "王五", "赵六", "田七", "张无忌", "肘子若", "赵敏", "张强", "张三丰");
        list.stream().filter(s -> s.startsWith("张")).forEach(System.out::println);

        ArrayList<Movie> movies = new ArrayList<>();
        movies.add(new Movie("唐顿庄园", 9.5, "张三丰"));
        movies.add(new Movie("三傻宝莱坞", 8.5, "阿米尔汗"));
        movies.add(new Movie("算加白",9.5,"阿米尔汗"));
        movies.add(new Movie("摔跤吧，爸爸", 9.5, "阿米尔汗"));
        movies.add(new Movie("三傻宝莱坞", 8.5, "阿米尔汗2"));

        movies.stream().sorted().forEach(s -> System.out.println(s));
        System.out.println("------------------");
        movies.stream().sorted((o1, o2) -> Double.compare(o2.getScore(), o1.getScore())).forEach(System.out::println);
        System.out.println("------------------");

        movies.stream().sorted((o1, o2) -> Double.compare(o2.getScore(), o1.getScore())).skip(2).forEach(System.out::println);

        System.out.println("------------------");
        movies.stream().sorted((o1, o2) -> Double.compare(o2.getScore(), o1.getScore())).distinct().forEach(System.out::println);
        System.out.println("------------------");
        movies.stream().map(m -> {
            m.setScore(m.getScore() + 2);
            return m;
        }).forEach(System.out::println);

        Stream<String> s1 = Stream.of("樟树湾", "小城", "小城", "小城", "小城", "小城");
        Stream<String> s2 = Stream.of("小城", "小城", "小城", "小城", "小城");
        Stream<String> allStream = Stream.concat(s1, s2);
        long count = allStream.count();
        System.out.println(count);
    }
}
